package com.shanzmoo.db.third.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.db.product.entity.vo.ThirdSkuQueryVO;
import com.shanzmoo.db.third.entity.ThirdProductSkuEntity;
import com.shanzmoo.db.third.mapper.ThirdProductSkuMapper;
import com.shanzmoo.db.third.service.IThirdProductSkuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 第三方商品sku 服务实现类
 * </p>
 *
 * @author Xueqz
 * @since 2021-01-09
 */
@Service
public class ThirdProductSkuServiceImpl extends ServiceImpl<ThirdProductSkuMapper, ThirdProductSkuEntity> implements IThirdProductSkuService {

    @Override
    public SResponse<Boolean> addThirdProductSkuEntity(ThirdProductSkuEntity thirdProductSkuEntity) {
        baseMapper.insert(thirdProductSkuEntity);
        return SResponse.ok();
    }

    @Override
    public SResponse<PageRespBase<ThirdProductSkuEntity>> getThirdProductSkuList(ThirdSkuQueryVO thirdSkuQueryVO) {
        // 开启分页
        Page page = PageHelper.startPage(thirdSkuQueryVO.getPageNum(), thirdSkuQueryVO.getPageSize());
        //获取信息 -- start
        List<ThirdProductSkuEntity> rsList = baseMapper.selectList(new QueryWrapper<ThirdProductSkuEntity>().eq("deleted", false));
        //获取信息 -- end
        PageRespBase<ThirdProductSkuEntity> re = PageRespBase.create(page, rsList);
        PageHelper.clearPage();
        return SResponse.ok(re);
    }
}
